<template>
  <div class="publicBox" id="terminalNewbuildCss">

<el-form ref="form"  class="demo-form-inline publicEditFrom" label-width="180px" label-position="left">

<el-row>
               <p class="pubPageTagP">终端设备管理/新建</p>
</el-row>

<el-row>
         <el-form-item label="SN">
                <el-input class="pubIptB"  v-model="ruleForm.sn"  placeholder="请输入设备SN号"></el-input>
                <el-button class="pubBtnBlue btn_left" @click="headleQuery" type="primary">查询</el-button>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="设备ID">
                 <p>{{rowData.no}}</p>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="品牌">
                 <p>{{rowData.brandname}}</p>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="型号">
                 <p>{{rowData.model}}</p>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="设备名称">
                <p>{{rowData.name}}</p>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="供应商">
                <p>{{rowData.suppliername}}</p>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="绑定通讯模块IMEI">
                 <el-input class="pubSerIpt" v-model="ruleForm.imei"  placeholder="请输入绑定通讯模块IMEI"></el-input>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="绑定设备编码">
                 <el-input class="pubSerIpt" v-model="ruleForm.deviceNo"  placeholder="请输入绑定设备编码"></el-input>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="所在仓库">
            <el-select v-model="ruleForm.warehouseType" filterable  placeholder="全部" class="pubSlt97">
                <el-option
                v-for="item in $warehouse()"
                :key="item.id"
                :label="item.name"
                :value="item.id">
                </el-option>
            </el-select>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="所在门店">
           <el-select v-model="ruleForm.storeId" filterable  placeholder="全部" class="pubSlt97">
                <el-option
                v-for="item in shopArray"
                :key="item.id"
                :label="item.name"
                :value="item.id">
                </el-option>
            </el-select>
       </el-form-item>
</el-row>

<el-row class="pubSubmitBtn-row">
      <el-form-item>
            <el-button class="pubBtnBlue" @click="addterminalNewbuild"  type="primary">保存</el-button>
            <el-button class="pubBtnGray" @click="$canCleFn"  type="primary">取消</el-button>
      </el-form-item>
</el-row>

</el-form>
    
  </div>
</template>

<script>
import * as API from "@api/equipmenter.js"
export default {
  components: {


  },
  data() {
    return {
      ruleForm:{
            sn:"",
             imei:"",
             deviceNo:"",
             warehouseType:"",
             storeId:""
      },
      shopArray:"",
      rowData:{}
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {


  },
  // 监控data中的数据变化
  watch: {


 },
  methods: {
       headleQuery(){
            var sn = this.ruleForm.sn
            if(sn === '' || sn === undefined){
                this.rowData = {}
                this.$message.warning("请输入设备SN号")
                return
            }
            API.getTerminalBySn(sn).then(res=>{
            if(res.IsPositive){
                    this.rowData = res.Data
                    console.log("res",res.Data)
                }else{
                    this.$message.error({message:res.ErrorCode})
            }               
            })               
         }, 
       async addterminalNewbuild(){  
            this.ruleForm.id=this.rowData.id
            let res = await API.editTerminalOnline(this.ruleForm)
            if(res.IsPositive){
              this.$message.success({message:"操作成功"})
              this.$router.push({path:'/platform/equipment/terminal'})
            }else{
              this.$message.error({message:res.ErrorCode})
            }
        },
       canCleFn(){
           this.$router.go(-1)
       }, 
  },
  async created() {
       await API.getShop().then(res=>{
              this.shopArray=res.Data.records
        })
     if(Object.keys(this.$route.query).length>0){              //ES6写法, Object.keys(targetObject)  将对象的key作为一个数组返回
                  
                  this.rowData=JSON.parse(data)
              //     console.log(this.rowData)
        }
  },
  mounted() {


  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='less'>
#terminalNewbuildCss{
               .btn_left{
            margin-left: 20px;
        }
}

</style>